package com.lucenly.spell.activity

import android.content.Context
import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.fragment.app.Fragment
import com.lucenly.spell.base.BaseActivity
import com.lucenly.spell.databinding.ActivityOrderBinding
import com.lucenly.spell.fragment.HomeItemFragment
import com.lucenly.spell.fragment.OrderFragment
import com.next.easynavigation.adapter.ViewPagerAdapter
import net.lucode.hackware.magicindicator.ViewPagerHelper
import net.lucode.hackware.magicindicator.buildins.UIUtil
import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView
import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ClipPagerTitleView

class OrderActivity() : BaseActivity<ActivityOrderBinding>() {
    var page : Int = 0
    val mTitleDataList = arrayListOf("全部","进行中","待支付","待发货","已发货","已完成")
    private val fragmentList = arrayListOf<Fragment>()
    override fun getViewBinding(): ActivityOrderBinding {
        return ActivityOrderBinding.inflate(layoutInflater,baseBinding.contentMain,true)
    }

    override fun setTitle(): String {
        return "我的订单"
    }

    override fun initData() {
        page = intent.getIntExtra("page",0)
        val commonNavigator = CommonNavigator(context)
        commonNavigator.isAdjustMode = true
//        commonNavigator.setBackgroundResource(R.drawable.bg_shape_ffffff_10)
        commonNavigator.adapter = object : CommonNavigatorAdapter() {
            override fun getCount(): Int {
                return mTitleDataList.size
            }

            override fun getTitleView(context: Context?, index: Int): IPagerTitleView? {
                val clipPagerTitleView  = ClipPagerTitleView(context)
                clipPagerTitleView.clipColor = Color.parseColor("#FFFF0742")
                clipPagerTitleView.textColor = Color.parseColor("#FF646464")
                clipPagerTitleView.text = mTitleDataList[index]
                clipPagerTitleView.textSize = UIUtil.dip2px(context,14.0).toFloat()
                clipPagerTitleView.setOnClickListener {
                    binding.viewpager.currentItem = index
                }
                return clipPagerTitleView
            }

            override fun getIndicator(context: Context?): IPagerIndicator? {
                val indicator = LinePagerIndicator(context)
                val navigatorHeight = UIUtil.dip2px(context, 3.0).toFloat()
                indicator.lineHeight = navigatorHeight
                indicator.setColors(Color.parseColor("#ff0742"))
                indicator.mode = LinePagerIndicator.MODE_WRAP_CONTENT
                return indicator
            }
        }
        binding.tab.navigator = commonNavigator
        for (i in 1..mTitleDataList.size){
            val fragment  = OrderFragment(i)
            fragmentList.add(fragment)
        }
        binding.viewpager.adapter = ViewPagerAdapter(supportFragmentManager, fragmentList)
        ViewPagerHelper.bind(binding.tab,binding.viewpager)
        binding.viewpager.currentItem = page
    }

    override fun initEvent() {
    }

    override fun startObserve() {
    }

}